home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 050a.dms / 050a.adf / TEXTS / chapter15.txt < prev    next >
Text File  |  1992-02-26  |  9KB  |  228 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                                Chapter fifteen
  4.                                ---------------
  5. Now I would like to show you an easy way to detect mouse selections.
  6. There are quite a few ways to set up menus that use the mouse but as we
  7. are trying to learn the basics I will show you the simplest way I could
  8. think of.  It`s not the best way but it is straight forward and neat.
  9.  
  10. If you have already looked at EXAMPLE15.Amos you will have seen how this 
  11. system works:
  12.  
  13. 1) We first print some text inside boxes onto the screen
  14. 2) We then detect if the user has pressed a mouse key
  15. 3) Act on the mouse click 
  16. 4) If inside a box perform the related task.
  17. 5) If outside a box then goto 2)
  18.  
  19. That is a broad outline of the program I will now go through the program
  20. line for line:
  21.  
  22. SCREEN OPEN 0,640,200,8,HIRES
  23. -----------------------------
  24. Open a custom screen, simply because it looks nice and gives more room for 
  25. text operations and the like.
  26.  
  27. CHANGE MOUSE 2: PAPER 6: CURS OFF: CLS 6
  28. ----------------------------------------
  29. Set the mouse pointer to a cross hair and switch the text cursor off, set
  30. text paper to the same as the background screen colour (6) a nice blue.
  31.  
  32. UNDER ON
  33. --------
  34. A new command but very straight forward.  This simply sets UNDERlined 
  35. text to ON, so any text PRINTed from now on will automatically be UNDERlined,
  36. at least until Amos comes to an UNDER OFF statement.
  37.  
  38. CENTRE "Move the mouse pointer over a box and click left button"
  39. ----------------------------------------------------------------
  40. Centralize the forthcoming string of text (This will be underlined as well) 
  41.  
  42. Note: As we haven`t set the text cursor to any specific position yet
  43.       the text will appear on line 0.
  44.  
  45. UNDER OFF
  46. ---------
  47. Now turn UNDERlining OFF.
  48.  
  49.  
  50. RESERVE ZONE 4
  51. --------------
  52. We will want four menu boxes in this example so we have to reserve space for
  53. them using RESERVE ZONE.  Don`t worry why at this stage just remember that
  54. the menus will not work without this command first.
  55.  
  56.  
  57. LOCATE 20,10: PRINT BORDER$(ZONE$("BOX 1",1),1)
  58. -----------------------------------------------
  59. We know what the LOCATE and PRINT instructions do.  
  60. The rest of the line is as follows:
  61.  
  62.  
  63. BORDER$(ZONE$(
  64. ---------------
  65. Is always the same (you can leave border$ out if you do not want the box)
  66.  
  67. "BOX 1"
  68. -------
  69. This is the text you wish to be displayed inside the menu box, in quotes.
  70.  
  71. ,1),1)
  72. ------
  73. The first number is the menu I.D for our use (1) and the second 1 is the type
  74. of border pattern we want around the box, ranges are 1 to 16 try out some
  75. different patterns in EXAMPLE15.Amos.  If you don`t want borders around your
  76. text then delete the first bracket and the ,1) at the end.
  77.  
  78. The next three lines are virtually the same except for the text and I.D 
  79. number.
  80.  
  81. DO
  82. --
  83. This is the start of the main loop. A DO LOOP structure in fact.  See last 
  84. line of this program for more details.
  85.  
  86.  
  87. WHILE MOUSE KEY=0: WEND
  88. -----------------------
  89. This excellent and useful little line continually loops until a mouse key is
  90. pressed where upon the program continues.  It is very similar to the WAIT KEY
  91. command we have been using but instead uses any mouse button. 
  92. Make a note of this mouse wait line for use in your future programs.  
  93. The WHILE WEND loop, as it is known, will repeat anything inside the WHILE 
  94. and WEND commands repeatedly until a condition is met, in this case a mouse 
  95. button click.  WHILE can be proceeded by as many commands as you need.
  96.  
  97.  
  98. KK=MOUSE ZONE
  99. -------------
  100. Really we do not need this line.  What it does is tells the variable KK to 
  101. hold the current zone number the mouse pointer is over.  If the mouse is not
  102. over any zone at all the value of kk (and mouse zone) will be zero.
  103. We will see why it`s not totally necessary in a moment. 
  104.  
  105. LOCATE 0,20
  106. -----------
  107. Set the text cursor to 0 across 20 down, ready for PRINTing to.
  108.  
  109. IF KK=1 THEN CENTRE "YOU SELECTED BOX 1"
  110. ----------------------------------------
  111. We could also have used IF MOUSE ZONE=1 but KK is quicker and neater to use.
  112. So if KK=1 (the zone the mouse pointer has been clicked over) THEN PRINT etc.
  113.  
  114. The following two lines are similar except for the text in the quotes.
  115.  
  116. IF KK=4 THEN CENTRE "YOU SELECTED EXIT": WAIT 50: EDIT
  117. ------------------------------------------------------
  118. We have used box 4 as an exit to the program. WAIT enough time for the user
  119. to read the message then goto EDIT mode.
  120.  
  121. LOOP
  122. ----
  123. The mouse key was pressed but KK was not equal to 1,2,3 or 4 so no box was
  124. clicked on (KK equal to 0) so we jump back to the DO part of the DO LOOP
  125. sequence and  start checking all over again.
  126.  
  127. EXAMPLE15.Amos will make it all clear.
  128. Spend a little time with this program and you could knock up some neat little
  129. menus.  How about a background picture with the boxes overlaid? Remember that
  130. when you use a picture the palette will change the system colours.
  131. By the way if you load a picture of a different size to a screen you have
  132. previously opened then Amos will change the size of the screen accordingly
  133. for you, so for example if you did this,
  134.  
  135. SCREEN OPEN 0,640,256,8,hires
  136.  
  137. Then you loaded a picture which was Lowres 320X200 then Amos would scrap
  138. your hires screen for the dimensions of the newly loaded picture.
  139.  
  140. The menu  program was good as far as simplicity goes but using a similar
  141. method with a few more commands we could make this menu system much more
  142. flexible and neater. Take a look at EXAMPLE15_1.Amos it`s quite an 
  143. improvement don`t you think?
  144.  
  145. As there are only a few commands we haven`t covered in EXAMPLE15_1.Amos and 
  146. as it is highly REMmed I will just explain the commands we haven't looked at
  147. yet.
  148.  
  149.  
  150. SET ZONE
  151. -------
  152. After using RESERVE ZONE we have to tell Amos exactly in coordinates where
  153. the top left and bottom right corners of each of our selection boxes are.
  154. In the previous example using ZONE$ Amos did this for us.
  155.  
  156. As the coordinates are hardware coordinates this is a pain so on this disk
  157. in the EXTRAS drawer you will find a program I wrote years ago called 
  158. GETZONE.Amos It will allow you to load an IFF picture or ABK SPACKED picture
  159. of any size you then click once on the top right corner of a menu box and 
  160. then the bottom right corner the hardware coordinates will then be displayed
  161. for you to write down, press a mouse key and you can do your next menu and so
  162. on. 
  163.  
  164. The good thing about this new menu system we are going to use is you are not
  165. limited to a box for your menu in fact it can be any rectangular shape or 
  166. size, within reason of course.
  167.  
  168. OK so we know our coordinates, we now need to let Amos know them too.
  169. This is where SET ZONE comes in to it.  In EXAMPLE15_1.Amos we have three 
  170. menu options so we need to set three zones, 1 to 3. These will be the I.D 
  171. numbers for our menus throughout the program.
  172.  
  173. SET ZONE 1,                    The menu I.D
  174.  
  175. SET ZONE 1, 256,93 TO          And coordinates of the top left edge of menu
  176.  
  177. SET ZONE 1, 256,93 TO 362,104  And the second set, bottom left coordinates
  178.   
  179. And that is it. Now just insert the rest of your coordinates like this:
  180.  
  181. SET ZONE 2,256,109 TO 362,109   
  182. etc.
  183.  
  184. Note: If like in the example program you are unpacking a screen then make 
  185. sure you unpack the screen BEFORE SETting ZONEs as they will be cleared.
  186.  
  187.  
  188. There are two more commands we have not covered from EXAMPLE15_1.Amos
  189. these are:
  190.  
  191. GOSUB
  192.  
  193. and
  194.  
  195. RETURN
  196.  
  197. These two commands are related, You GOSUB to a routine and then RETURN from
  198. it when completed.
  199.  
  200. GOSUB is almost the same as GOTO but has one extra powerful feature the 
  201. RETURN part, here is an example,
  202.  
  203.  
  204. GOSUB F1
  205. PRINT "I`VE BEEN TO F1"
  206. STOP
  207.  
  208.  
  209. F1:
  210. PRINT "I am now in a subroutine"
  211. RETURN
  212.  
  213.  
  214. The program goes to the part of the program labelled F1: and executes 
  215. commands until it reaches a RETURN instruction, and this is the good part, 
  216. the program then continues from the instruction immediately after the GOSUB 
  217. call.  So what! You may say, what use is that? Well what if we wanted to 
  218. execute the same routine lots of times during a program we just call it with
  219. GOSUB then continue executing from after the gosub as if nothing happened.
  220.  
  221. In Amos the GOSUB has taken a bit of a backseat because of a command called
  222. PROCEDURE and we will be covering that subject very soon, but now you know
  223. about GOTO and GOSUB PROCEDURE will be a lot easier to understand.
  224. For a good example of GOSUB check out Example15_1.Amos.
  225.  
  226.                            End of chapter fifteen
  227.                            ^^^^^^^^^^^^^^^^^^^^^^
  228.